<?php
/*
 * @Author: winner
 * @Date: 2022-04-13 17:19:16
 * @LastEditTime: 2022-04-27 11:15:06
 * @LastEditors: winner
 * @Description: 
 */


namespace app\api\controller;

use app\service\MerchantService;
use app\service\OrderService;

class Pay extends Common
{
    public function __construct()
    {
        // 调用父类前置方法
        parent::__construct();

    }

    /**
     * 上传附件
     * @date 2022-04-13 14:09
     */
    public function upload()
    {

        $pay_name = 'payment\\ImInPay';
        $ite = [
            ['name'=> '1650953036265391.jpg','path'=> 'https://shop.qmchat.site/static/upload/images/common/2022/04/26/1650953036265391.jpg'],
              ['name'=> '1650953034777734.jpg','path'=> 'https://shop.qmchat.site/static/upload/images/common/2022/04/26/1650953034777734.jpg'],
                ['name'=> '1650953035795342.jpg','path'=> 'https://shop.qmchat.site/static/upload/images/common/2022/04/26/1650953035795342.jpg'],
        ['name' => '1650953037586057.jpg', 'path' => 'https://shop.qmchat.site/static/upload/images/common/2022/04/26/1650953037586057.jpg']
        ];
        $parames = [];

        foreach ($ite as $key => $value) {
            $ret = (new $pay_name([]))->upload($value);
            $parames[] = $ret['merQualUrl'];
        }
        var_dump($parames);

        //$ret = (new $pay_name([]))->upload([]);

    }
    public function test()
    {

        
       $dd = ['id','in',[1,3,4,5]];
        $bank_ret = MerchantService::GetBankRegion(['priovince'=>1,'city'=>2,'mepriocine'=>15]);
        var_dump($bank_ret);
        exit();
        $code_ret = MerchantService::code([
            'head_bankno' => "JHYH",
            'bank_province' => "330000",
            'bank_city' => "330300"
        ]);
        echo array_keys($code_ret['branchBankInfo'])[0];
        $ret = MerchantService::GetBankRegion();
        var_dump($ret);
    }

    /**
     * 入网
     * @date 2022-04-13 14:09
     */
    public function in()
    {
        $pay_name = 'payment\\ImInPay';

        $ret = (new $pay_name([]))->inthree([]);
    }


    public function code()
    {
        $pay_name = 'payment\\ImInPay';

        $ret = (new $pay_name([]))->code([]);
    }
    public function divide()
    {
        //$order = $this->data_request;
         $pay_name = 'payment\\ImPay';
        // $list = MerchantService::deviledtest(['where'=>'frozen_amount > 0']);
        // $amount = 0;
        // foreach ($list as &$v) {
        //     $v['amount'] = $v['frozen_amount'];
        //     $v['up_order_id'] =$v['trade_no'];
        //     $ret = (new $pay_name([]))->divide($v);
        //     if ($ret['status'] == 100 && $ret['state'] != 1) {
        //         $amount += $v['amount'];
        //         $order_ret = MerchantService::updateorder($v);
        //         echo $ret['status'] . ' | ' . $ret['message'] . ' | ' . ' | ' . $ret['state'] . ' | ' . $v['order_no'] . '<br>';
        //         echo '当前额度：' . $v['amount'] . ',总额度：' . $amount . '<br>';
        //     } else {
        //         var_dump($ret);
        //         echo "<br>";
        //     }
        // }
        // exit();


        $orders = [
            ['up_order_id' => '91517421261160058880', 'order_no' => '20220422163146972086','amount'=> 9671.4]
        ];

    $online_orders = [
            ['up_order_id' => '91516400194018611200', 'order_no' => '20220419205553468690', 'amount' => 5356.8],
            ['up_order_id' => '91516360265217609728', 'order_no' => '20220419181713077425', 'amount' => 176.58],
            ['up_order_id' => '91516366991836975104', 'order_no' => '20220419184357789694', 'amount' => 2083.2],
            ['up_order_id' => '91516372098225803264', 'order_no' => '20220419190414933472', 'amount' => 2083.2]
    ];
        //$ret = (new $pay_name([]))->divide(['up_order_id' => '91516631226735136768', 'order_no' => '20220413184127329281', 'amount' => 0.99]);
        $amount =0;
        foreach ($online_orders as &$v) {
            $ret = (new $pay_name([]))->divide($v);
            if($ret['status']==100 && $ret['state'] !=1){
                $amount+=$v['amount'];
               // $order_ret = MerchantService::updateorder($v);
                echo $ret['status'] . ' | ' . $ret['message'] . ' | ' . ' | ' . $ret['state'] . ' | ' . $v['order_no'] . '<br>';
                echo '当前额度：' . $v['amount'] . ',总额度：' . $amount.'<br>';
            }else {
                var_dump($ret);
                echo "<br>";
            }
           
        }




    }

}